package cn.yunhe.java;

import cn.yunhe.java.dto.MerchantDTO;
import cn.yunhe.java.util.TokenUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huiminpay.common.cache.util.EncryptUtil;
import cn.yunhe.java.service.IMerchantService;
import com.huiminpay.common.cache.util.LoginUser;
import org.apache.dubbo.config.annotation.Reference;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;


@RunWith(SpringRunner.class)
@SpringBootTest
public class TokenTemp {

    @Reference
    IMerchantService merchantService;

    //生成token，指定商户id
    @Test
    public void createTestToken() {
        Long merchantId = 1406243555940507649L;//填写用于测试的商户id
        MerchantDTO merchantDTO = merchantService.queryMerchantById(merchantId);
        JSONObject token = new JSONObject();
        token.put("mobile", merchantDTO.getMobile());
        token.put("user_name", merchantDTO.getUsername());
        token.put("merchantId", merchantId);
        token.put("tenantId",merchantDTO.getTenantId());

        String jwt_token = "Bearer " + EncryptUtil.encodeBase64(JSON.toJSONString(token).getBytes());
        System.out.println(jwt_token);
        //Bearer eyJtZXJjaGFudElkIjoxNDA2MjQzNTU1OTQwNTA3NjQ5LCJ1c2VyX25hbWUiOiJzdHJpbmciLCJtb2JpbGUiOiIxMjMxMjIyMiIsInRlbmFudElkIjoxMjM0NTZ9
    }

//    token转对象测试
    @Test
    public void test2(){
        LoginUser user = TokenUtil.parseToken("eyJtZXJjaGFudElkIjoxNDA2MjQzNTU1OTQwNTA3NjQ5LCJ1c2VyX25hbWUiOiJzdHJpbmciLCJtb2JpbGUiOiIxMjMxMjIyMiIsInRlbmFudElkIjoxMjM0NTZ9", LoginUser.class);
        System.out.println(user);
    }


}
